package com.webapp.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.webapp.domain.entity.Attachment;

/**
 * 咨纠纷询附件DAO
 * @author zern
 *
 */
@Repository("attachmentDAO")
public class AttachmentDAO extends AbstractDAO<Attachment>{

	/**
	 * 删除纠纷附件咨询（伪删除）
	 * @param id
	 * @return
	 */
	public int deleteAttachment(String id){
		String hql = "update Attachment a set a.delFlag = '1' where a.id = :id";
		Query query = getSession().createQuery(hql);
		
		query.setString("id", id);
		return query.executeUpdate();
	}
	
	/**
	 * 查询纠纷咨询下的所有附件
	 * @param dataId
	 * @return
	 */
	public List<Attachment> findAttachmentsByDisData(String dataId){
		
		String hql = "from Attachment a where a.disputesData.id = :id and a.delFlag = 0 order by a.type";
		Query query = getSession().createQuery(hql);
		query.setString("id", dataId);
		return query.list();
	}
}
